from typing import List
from datetime import datetime
from dataclasses import dataclass, asdict, fields

from ._orginal import Orginal

@dataclass(init=False)
class Details:
    parent_model: str
    format: str
    family: str
    families: List[str]
    parameter_size: str
    quantization_level: str
    
    def __init__(self, **kwargs):
        names = set([f.name for f in fields(self)])
        for k, v in kwargs.items():
            if k in names:
                setattr(self, k, v)

@dataclass(init=False)
class Model:
    name: str
    model: str
    size: int
    digest: str
    details: Details
    expires_at: datetime
    size_vram: int
    
    def __init__(self, **kwargs):
        names = set([f.name for f in fields(self)])
        for k, v in kwargs.items():
            if k in names:
                setattr(self, k, v)

@dataclass(init=False)
class Ps(Orginal):
    models: List[Model]

    def __init__(self, orginal=None, **kwargs):
        super().setOrginal(orginal)
        names = set([f.name for f in fields(self)])
        for k, v in kwargs.items():
            if k in names:
                setattr(self, k, v)



if __name__ == "__main__":
    ps_json = '''
    {
        "models": [
            {
                "name": "qwen2.5:0.5b",
                "model": "qwen2.5:0.5b",
                "size": 820601088,
                "digest": "a8b0c51577010a279d933d14c2a8ab4b268079d44c5c8830c0a93900f1827c67",
                "details": {
                    "parent_model": "",
                    "format": "gguf",
                    "family": "qwen2",
                    "families": [
                        "qwen2"
                    ],
                    "parameter_size": "494.03M",
                    "quantization_level": "Q4_K_M"
                },
                "expires_at": "2025-01-07T06:29:10.312269303Z",
                "size_vram": 0
            }
        ]
    }
    '''

    import json

    print(Ps(**json.loads(ps_json)))